import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class AWTLayout extends JFrame implements ActionListener {
    JTextField tf = new JTextField(10);
    JButton bt = new JButton("OK");
    static int i = 0;

    public AWTLayout() {
        super("图形用户界面框架");
        Container c = getContentPane(); // 获得窗口的内容显示层
        c.setLayout(new FlowLayout()); // 设置显示层的布局方式
        c.add(tf); // 添加组件
        c.add(bt);
        setSize(200, 100);
        setVisible(true); // 显示窗口界面
        bt.addActionListener(this);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

    public void actionPerformed(ActionEvent e) {
        i = i + 1;
        if (i % 2 == 0)
            tf.setText("单机1次");
        else
            tf.setText("双击1次");
    }

    public static void main(String args[]) {
        new AWTLayout();
    }
}